package esayexcel.demo;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;

public class Test {
    static final ThreadLocal<List<String>> THREAD_LOCAL = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        List<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10; i++) {
            System.out.println("第【"+i+"】次调用");
            list.add(i + "_" +System.currentTimeMillis() + Thread.currentThread().getName());
            extracted(list,i);
        }
        THREAD_LOCAL.remove();
    }

    private static  void  extracted(List<String> list,int i) throws InterruptedException {
        new Thread(() -> {
            callThis(list, i);
        }).start();

    }

    private static void  callThis(List<String> list, int i) {
        if (CollectionUtils.isEmpty(THREAD_LOCAL.get())) {
            THREAD_LOCAL.set(list);
        }
        System.out.println("线程 [ "+ i +" ] - list == " + THREAD_LOCAL.get());
    }
}
